#!/usr/bin/env python
# -*- coding:utf-8 -*-


'''
@Author : shouke
'''

# import gevent
from locust.env import Environment
# from locust.stats import stats_printer, stats_history
from locust.log import setup_logging
from config.config import log_level, web_ui_host, web_ui_port, master_bind_host, master_bind_port
from locust.contrib.fasthttp import FastHttpUser
import logging

setup_logging(log_level, None)
logger = logging.getLogger(__name__)


class User(FastHttpUser):
    pass

if __name__ == '__main__':
    # 设置环境
    env = Environment(user_classes=[User])
    env.create_master_runner(master_bind_host=master_bind_host, master_bind_port=master_bind_port)

    # 创建WebUI实例用于提供web服务
    env.create_web_ui(web_ui_host, web_ui_port)

    # 启动一个greenlet(协程)用于周期性的输出当前性能统计数据 #LocustPlus 类库里面已经自动启动了
    # gevent.spawn(stats_printer(env.stats))

    # # 启动一个greenlet用于保存当前性能统计数据
    # gevent.spawn(stats_history, env.runner)

    # 等待greenlets全部结束
    env.runner.greenlet.join()

    # 停止webui 服务
    env.web_ui.stop()
